package com.foreveross.bsl.view;

import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.foreveross.bsl.test.R;


public class CustomPopupWindow extends PopupWindow {


	private Button btn_cancel;
	private View mMenuView;
	private TextView mTitle;
	private TextView mContent;
	private View mBgView;
	public CustomPopupWindow(Activity context,OnClickListener itemsOnClick) {
		super(context);
		LayoutInflater inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		mMenuView = inflater.inflate(R.layout.alert_dialog, null);
		mTitle = (TextView)mMenuView.findViewById(R.id.title);
		mBgView = mMenuView.findViewById(R.id.pop_layout);
		mContent = (TextView)mMenuView.findViewById(R.id.text);
		btn_cancel = (Button) mMenuView.findViewById(R.id.btn_cancel);
		btn_cancel.setOnClickListener(new OnClickListener() {

			public void onClick(View v) {
				dismiss();
			}
		});
		this.setContentView(mMenuView);
		this.setWidth(LayoutParams.FILL_PARENT);
		this.setHeight(LayoutParams.WRAP_CONTENT);
		this.setFocusable(true);
		this.setAnimationStyle(R.style.AnimBottom);
		ColorDrawable dw = new ColorDrawable(0xb0000000);
		this.setBackgroundDrawable(dw);
		mMenuView.setOnTouchListener(new OnTouchListener() {
			
			public boolean onTouch(View v, MotionEvent event) {
				
				int height = mMenuView.findViewById(R.id.pop_layout).getTop();
				int y=(int) event.getY();
				if(event.getAction()==MotionEvent.ACTION_UP){
					if(y<height){
						dismiss();
					}
				}				
				return true;
			}
		});

	}
	
	public void setMsg(String title,String content) {
		mTitle.setText(title);
		mContent.setText(content);
	}
	
	public void setTitleColor(int color) {
		mTitle.setTextColor(color);
	}
	
	public void setContentColor(int color) {
		mContent.setTextColor(color);
	}
	
	public void setBg(int resid) {
		mBgView.setBackgroundResource(resid);
	}
	
	public void setBg(Drawable draw) {
		mBgView.setBackgroundDrawable(draw);
	}
	
	public void setBgColor(int color) {
		mBgView.setBackgroundColor(color);
	}
}
